<template>
  <div class="dynamics">
    <div class="dynamics-title">公司动态</div>
    <div class="dynamics-list">
      <div class="dynamics-item" v-for="(item, index) in dynamicsList">
        <div class="dynamics-img">
          <img :src="item.imgUrl" alt="" />
        </div>
        <div class="dynamics-item-date">{{ item.date }}</div>
        <div class="dynamics-item-title">{{ item.title }}</div>
        <div class="dynamics-item-txt">{{ item.txt }}</div>
        <div class="mask mask-left" @click="previous" v-if="index == 0"><</div>
        <div class="mask mask-right" @click="next" v-if="index == 3">></div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, nextTick } from "vue";
const arr = ref([
  {
    imgUrl:
      "https://cdn.leweisoft.com/mh/website/lewei/info-image1-450-new.jpg",
    title: "乐维科技：2023年成绩斐然，已初步形成互联网商业生态系统",
    date: "2013/13/11",
    txt: "2023年的乐维科技正在逐渐形成自己的互联网商业生态系统，同时对外开放生态合作，与更多合作伙伴携手创造共赢，帮助客户实现业务价值的最大化。",
  },
  {
    imgUrl:
      "https://cdn.leweisoft.com/mh/website/lewei/info-image1-450-new.jpg",
    title: "乐维科技：2023年成绩斐然，已初步形成互联网商业生态系统",
    date: "2015/13/11",
    txt: "2023年的乐维科技正在逐渐形成自己的互联网商业生态系统，同时对外开放生态合作，与更多合作伙伴携手创造共赢，帮助客户实现业务价值的最大化。",
  },
  {
    imgUrl:
      "https://cdn.leweisoft.com/mh/website/lewei/info-image1-450-new.jpg",
    title: "乐维科技：2023年成绩斐然，已初步形成互联网商业生态系统",
    date: "2016/13/11",
    txt: "2023年的乐维科技正在逐渐形成自己的互联网商业生态系统，同时对外开放生态合作，与更多合作伙伴携手创造共赢，帮助客户实现业务价值的最大化。",
  },
  {
    imgUrl:
      "https://cdn.leweisoft.com/mh/website/lewei/info-image1-450-new.jpg",
    title: "乐维科技：2023年成绩斐然，已初步形成互联网商业生态系统",
    date: "2017/13/11",
    txt: "2023年的乐维科技正在逐渐形成自己的互联网商业生态系统，同时对外开放生态合作，与更多合作伙伴携手创造共赢，帮助客户实现业务价值的最大化。",
  },
  {
    imgUrl:
      "https://cdn.leweisoft.com/mh/website/lewei/info-image3-450-new.jpg",
    title: "乐维科技：2023年成绩斐然，已初步形成互联网商业生态系统",
    date: "2018/13/11",
    txt: "2023年的乐维科技正在逐渐形成自己的互联网商业生态系统，同时对外开放生态合作，与更多合作伙伴携手创造共赢，帮助客户实现业务价值的最大化。",
  },
]);
const dynamicsList = ref([]);
function getCircularSubarray(arr, n = 4, c = 0) {
  c = c % (n + 1);
  const length = arr.value.length;
  if (length === 0) return [];
  dynamicsList.value = [];
  for (let i = c; i < n + c; i++) {
    dynamicsList.value.push(arr.value[i % length]);
  }
}
let frequency = 0;
getCircularSubarray(arr, 4, frequency);
function previous() {
  frequency--;
  if (frequency <= 0) {
    frequency = 3;
  }
  nextTick(() => {
    getCircularSubarray(arr, 4, frequency);
  });
}
function next() {
  frequency++;
  nextTick(() => {
    getCircularSubarray(arr, 4, frequency);
  });
}
</script>
<style scoped lang='less'>
.dynamics {
  width: 75.591vw;
  margin: 0 auto;
  padding-bottom: 60px;
  .dynamics-title {
    font-size: 1.575vw;
    font-weight: 700;
    text-align: center;
    padding: 0.787vw 0 3.11vw 0;
    color: #333;
  }
  .dynamics-list {
    display: flex;
    justify-content: space-between;
    .dynamics-item {
      position: relative;
      width: 17.717vw;
      height: 18.898vw;
      border-radius: 0.591vw;
      overflow: hidden;
      border: 0.039vw solid #e6e6e6;
      cursor: pointer;
      .mask {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 10;
        width: 100%;
        height: 100%;
        background-color: #00000077;
        font-size: 4.331vw;
        font-family: serif;
        color: #fffefe;
        line-height: 18.898vw;
      }
      .mask-left {
        text-align: right;
        padding-right: 1.969vw;
      }
      .mask-right {
        padding-left: 1.969vw;
      }
      .dynamics-img {
        width: 17.717vw;
        height: 7.874vw;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .dynamics-item-date {
        position: relative;
        z-index: 1;
        width: 5.433vw;
        height: 1.024vw;
        border-radius: 0.197vw;
        margin: 0 auto;
        margin-top: -0.512vw;
        font-size: 0.551vw;
        font-family: PingFang;
        font-weight: 400;
        color: #fff;
        line-height: 1.102vw;
        text-align: center;
        background: linear-gradient(90deg, #508bff, #6567dc);
      }
      .dynamics-item-title {
        font-size: 0.709vw;
        font-family: PingFang;
        font-weight: 800;
        color: #333;
        text-align: center;
        padding: 1.969vw 0 1.535vw 0;
      }
      .dynamics-item-txt {
        font-size: 0.551vw;
        font-family: PingFang;
        font-weight: 400;
        color: #999;
        line-height: 1.102vw;
        padding: 0 1.339vw;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        text-align: center;
      }
    }
    .dynamics-item:nth-child(2):hover img {
      transform: scale(1.1);
    }
    .dynamics-item:nth-child(3):hover img {
      transform: scale(1.1);
    }
    .dynamics-item:nth-child(2):hover .dynamics-item-title {
      color: #497bff;
    }
    .dynamics-item:nth-child(3):hover .dynamics-item-title {
      color: #497bff;
    }
  }
}
</style>